﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoxFire : MonoBehaviour
{
    public Transform a;
    public Transform b;

    private float trans_a_x;
    private float trans_b_x;

    public GameObject[] prefabs;

    public bool stop = false;

    // Start is called before the first frame update
    void Start()
    {
        trans_a_x = a.position.x;
        trans_b_x = b.position.x;

        StartCoroutine(Fire());
    }

    // 方块开火
    IEnumerator Fire()
    {
        while(!stop)
        {
            int r = Random.Range(0, 6);

            float position_x = Random.Range(trans_a_x, trans_b_x);
            float rotation = Random.Range(0, 2);

            GameObject temp = Instantiate(prefabs[r]);
            temp.transform.position = new Vector3(position_x, gameObject.transform.position.y, 0);
            temp.transform.Rotate(new Vector3(0, 0, rotation * 90));

            yield return new WaitForSeconds(4f);
        }
    }
}
